<!--
 * @Author: 刘十三
 * @Date: 2023-12-28 14:56:27
 * @LastEditors: 刘十三
 * @LastEditTime: 2024-01-10 14:29:01
 * @FilePath: \dev-1.3.1-nm\dev\pages\internal\linkage\todo\components\informationCompletion.vue
 * @Description: 内蒙多员联动 - 信息录入审批（任务办结表单）
-->

<template>
  <view class="form-main">
    <u-form class="u-form-m" :model="completionForm" :error-type="['border-bottom', 'toast']" label-width="auto" label-position="top" ref="uForm">
      <u-form-item label="核查安排确认意见" prop="handleComment" :required="isEdit">
        <u-input placeholder="请输入" v-model="completionForm.handleComment" type="textarea" height="100" :auto-height="true" :disabled="!isEdit" maxlength="200" />
      </u-form-item>
      <u-form-item label="办结记录结果" prop="executeResult" :required="isEdit">
        <u-input placeholder="请输入" v-model="completionForm.executeResult" type="text" maxlength="100" v-if="isEdit" />
        <view style="font-size: 16px;line-height:1.5" v-else>{{ completionForm.executeResult }}</view>
      </u-form-item>
      <u-form-item label="任务办结" prop="id">
        <view v-if="!isEdit && fileList.length == 0">
          <u-icon name="attach" color="#2979ff" size="28"></u-icon>
          <span style="font-size: 16px;color: #393B3D;">未上传</span>
        </view>
        <m-upload :deletable="isEdit" :disabled="!isEdit" :maxCount="10" width="150rpx" height="150rpx" :file-list="fileList" :multiple="true" index="doorwayUpload" :uploadParam="{ fiGroupCode: $FILE_GROUP_TYPE.l_diversification_attr, bizId: completionForm.id }" upApiUrl="uploadBase64ForApp" ref="filePicUpload" @on-list-change="handleUpdate" />
      </u-form-item>
      <u-form-item label="" prop="" :border-bottom="false">
        <u-row style="width:100%">
          <u-col span="12" class="left-label" text-align="right">{{ completionForm.handlePersonsDeptName }}：{{ completionForm.handlePersonsName }}</u-col>
          <u-col span="12" class="right-label" text-align="right">{{ completionForm.createdAt || "---" }}</u-col>
        </u-row>
      </u-form-item>
    </u-form>
  </view>
</template>

<script>
import commonService from "@/service/common/common.service";
import mUpload from "@/components/m-upload.vue";
import moment from "moment";
import { uuid } from "@/common/util.js";
export default {
  components: { mUpload },
  name: "informationCompletion",
  props: {
    isEdit: {
      type: Boolean, // 是否可以编辑  false 不可以编辑
      default: false,
    },
    form: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      completionForm: {
        id: "",
        executeResult: "", // 办结记录结果
        handleComment: "", // 核查意见
        nextHandlePersonsId: "", // 下一级审批人ID
        nextHandlePersonsName: "", //  下一级审批人NAME
        handlePersonsName: "", // 当前人
        createdAt: "", // 当前时间
        handlePersonsDeptName: "", //当前人的组织name
      },
      rules: {
        executeResult: [
          {
            required: true,
            message: "请输入办结记录结果",
            trigger: ["blur", "change"],
          },
        ],
        handleComment: [
          {
            required: true,
            message: "请输入核查安排确认意见，最多200个字",
            trigger: ["blur", "change"],
          },
        ],
      },
      fileList: [],
    };
  },
  methods: {
    getCurDate() {
      return moment().format("YYYY-MM-DD");
    },
    handleUpdate(list) {
      if (list.length > 0) {
        this.fileList = [...list];
      } else {
        this.fileList = [];
      }
    },
    getFile(uuid) {
      commonService.goFiles(uuid, this.$FILE_GROUP_TYPE.l_diversification_attr).then((rs) => {
        if (rs.success) {
          if (rs.data.length > 0) {
            rs.data.forEach((item) => {
              this.fileList.push({ fileId: item.gfiId, gfiId: item.gfiId });
            });
          }
        } else {
          this.$u.toast(rs.msg);
        }
      });
    },
  },
  mounted() {
    if (this.isEdit) {
      this.$refs.uForm.setRules(this.rules);
      this.completionForm.id = uuid();
      this.completionForm.handlePersonsDeptName = this.curUser.deptName;
      this.completionForm.handlePersonsName = this.curUser.user.personName;
      this.completionForm.createdAt = this.getCurDate();
    } else {
      this.completionForm = this.form;
      this.getFile(this.completionForm.id);
    }
  },
};
</script>

<style lang="scss" scoped>
.u-form-m {
  padding: 0px 5px;
}
</style>
